const {spawn} = require('node:child_process');
const {resolve} = require('node:path');

// Elasticsearch 及 NW.js 应用的路径
const elasticsearchBinPath = resolve('./cache/elasticsearch-8.11.4/bin/');
const elasticsearchCommand = resolve(elasticsearchBinPath, 'elasticsearch');

// 启动 Elasticsearch 进程
const elasticsearchProcess = spawn(elasticsearchCommand, [], {
  stdio: 'inherit',
  detached: true, // 让 Elasticsearch 进程成为新的进程组的领头进程
});


// 监听 Elasticsearch 进程的退出事件
elasticsearchProcess.on('exit', (code, signal) => {
  console.log(`Elasticsearch process exited with code ${code} and signal ${signal}`);
});

